package com.csr.csrcheck.service.impl;


import com.csr.csrcheck.mapper.Five_SupplierMapper;
import com.csr.csrcheck.pojo.Five_supplier;
import com.csr.csrcheck.service.Five_SupplierService;
import com.csr.csrcheck.service.ex.CompanyException;
import com.csr.csrcheck.util.PageResult;
import com.csr.csrcheck.util.PageUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class Five_SupplierServiceImpl implements Five_SupplierService {
    @Resource
    private Five_SupplierMapper fiveSupplierMapper;

    public PageResult getListFive(int pageNum, int pageSize, String supplier_name) {
        return PageUtils.getPageResult(pageNum, pageSize, getPageInfo(pageNum, pageSize, supplier_name));
    }

    public int addFivesupplier(Five_supplier five_Supplier) {
        int row = this.fiveSupplierMapper.addFivesupplier(five_Supplier);
        if (row != 1)
            throw new CompanyException("");
        return row;
    }

    public int updateFiveSupplier(Five_supplier five_Supplier) {
        int row = this.fiveSupplierMapper.updateFiveSupplier(five_Supplier);
        if (row != 1)
            throw new CompanyException("");
        return row;
    }

    public int deleteFiveSupplier(int id) {
        int row = this.fiveSupplierMapper.deleteFiveSupplier(id);
        if (row != 1)
            throw new CompanyException("");
        return row;
    }

    public Five_supplier fingfiveByid(int id) {
        return this.fiveSupplierMapper.fingfiveByid(id);
    }

    private PageInfo<Five_supplier> getPageInfo(int pageNum, int pageSize, String supplier_name) {
        PageHelper.startPage(pageNum, pageSize);
        List<Five_supplier> list = this.fiveSupplierMapper.getListFive(supplier_name);
        if (list == null)
            throw new CompanyException("");
        return new PageInfo(list);
    }
}
